package cn.hjh.service;


import cn.hjh.dao.EmployeeDao;
import cn.hjh.dao.HibernateUtil;
import cn.hjh.pojo.Employee;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;

import java.util.List;

public class EmployeeBiz {

    private EmployeeDao dao = new EmployeeDao();

    public void addNewEmployee(Employee employee) {
        Transaction tx = null;
        try {
            tx = HibernateUtil.currentSession().beginTransaction();
            dao.save(employee);
            tx.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            if (tx != null) {
                tx.rollback();
            }
        }
    }

    public List<Employee> findEmployee() {
        Transaction tx = null;
        List<Employee> list = null;
        try {
            tx = HibernateUtil.currentSession().beginTransaction();
            list = dao.findEmployee();
            tx.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            if (tx != null) {
                tx.rollback();
            }
        }
        return list;
    }
}